package com.demo.controller;

import com.demo.models.News;
import com.jfinal.core.Controller;

public class NewsController extends Controller {

	//每页的数量
	private static final int PAGE_SIZE = 3;
	
	public void scan() {
		if (getPara() != null ) {
			int cateIndex = getParaToInt(0);
			int pageIndex = getParaToInt(1, 1);
			if (cateIndex > 0) {
				String cate = News.cateList.get(cateIndex);
				setAttr("newsPage", News.me.paginate(cate, pageIndex, PAGE_SIZE));
				setAttr("cateIndex", cateIndex);
			} else {
				setAttr("newsPage", News.me.paginate( pageIndex, PAGE_SIZE));
				setAttr("cateIndex", "n1");
			}
			setAttr("pageIndex", pageIndex);
		} else {
			setAttr("cateIndex", "n1");
			setAttr("newsPage", News.me.paginate( 1, PAGE_SIZE));
		}
		setAttr("cateList", News.cateList);
		render("news.html");
	}
	
	public void detail() {
		render("new_lb.html");
	}
}
